<template>
  <div class="mycenter">
    <x-header>
      个人中心
      <div slot="right">
        <router-link to="/setting">设置</router-link>
      </div>
    </x-header>
    <div class="user">
      <div class="userImg"> </div>
      <p class="name">{{username}}</p>
    </div>
    <div class="order">
      <tab :line-width='2' active-color='#ffa534' default-color='#333' custom-bar-width='50' :scroll-threshold="5">
        <tab-item @on-item-click='changeTab' selected>全部订单</tab-item>
        <tab-item @on-item-click='changeTab'>待付款{{'('+orderCount.nopay+')'}}</tab-item>
        <tab-item @on-item-click='changeTab'>待发货{{'('+orderCount.delivery+')'}}</tab-item>
        <tab-item @on-item-click='changeTab'>待收货{{'('+orderCount.collect+')'}}</tab-item>
        <tab-item @on-item-click='changeTab'>已完成</tab-item>
      </tab>
    </div>
    <div class="orderList">
      <div class="allList" v-if="tab == 0">
        <order-item :list="orderList"></order-item>
      </div>
      <div v-else-if="tab == 1" class="nopay">
        <order-item :list="nopay"></order-item>
      </div>
      <div v-else-if="tab == 2" class="delivery">
        <order-item :list="delivery"></order-item>
      </div>
      <div v-else-if="tab == 3" class="collect">
        <order-item :list="collect"></order-item>
      </div>
      <div v-else-if="tab == 4" class="complete">
        <order-item :list="complete"></order-item>
      </div>
    </div>
  </div>
</template>

<script>
import orderItem from './orderItem';

export default {
  components: { 'order-item': orderItem },
  data() {
    return {
      username: sessionStorage.getItem('username'),    //用户名
      userImg: '',   //用户头像图片地址
      tab: 0,         //订单tab激活下标
      //相应状态订单数量
      orderCount: {
        nopay: 1,     //未付款
        delivery: 1,  //待发货
        collect: 1,     //待收货
      },
      //所有订单列表
      orderList: [
        {
          id: 1,
          shop: '花之林',
          status: '待付款',
          products: [
            { id: 1, name: '粉色多头玫瑰', type: '粉色', price: '58', count: 1, url: 'assets/flower1.jpg' },
          ],
          postage: '0.00',
          total: '88',
        },
        {
          id: 2,
          shop: '花之都',
          status: '待发货',
          products: [
            { id: 1, name: '黄色多头玫瑰', type: '黄色', price: '58', count: 1, url: 'assets/flower2.jpg' },
          ],
          postage: '0.00',
          total: '88',
        },
        {
          id: 3,
          shop: '花丛林',
          status: '卖家已发货',
          products: [
            { id: 1, name: '白色多头玫瑰', type: '白色', price: '58', count: 1, url: 'assets/flower3.jpg' },
          ],
          postage: '0.00',
          total: '88',
        },
        {
          id: 4,
          shop: '花海洋',
          status: '已完成',
          products: [
            { id: 1, name: '红色多头玫瑰', type: '红色', price: '58', count: 1, url: 'assets/flower4.jpg' },
          ],
          postage: '0.00',
          total: '88',
        }
      ],
    }
  },
  computed: {
    nopay() {
      return this.orderList.filter(item => item.status == '待付款')
    },
    delivery() {
      return this.orderList.filter(item => item.status == '待发货')
    },
    collect() {
      return this.orderList.filter(item => item.status == '卖家已发货')
    },
    complete() {
      return this.orderList.filter(item => item.status == '已完成')
    }
  },
  methods: {
    //订单状态tab切换
    changeTab(e) {
      this.tab = e;
    },
  }
}
</script>

<style lang="less" scoped>
.user {
  height: 140px;
  text-align: center;
  padding-top: 20px;
  background: #ededed;
  box-sizing: border-box;
  .userImg {
    height: 60px;
    width: 60px;
    margin: 0 auto;
    border-radius: 50%;
    background: #fff;
    margin-bottom: 20px;
  }
}
.vux-tab-item-badge {
  margin: auto 0 !important;
}
.orderList {
  margin-bottom: 53px;
}
</style>
